package com.aaa.listener;

import org.apache.log4j.PropertyConfigurator;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

/**
 * @author ：肖成杰（1752167034@qq.com）
 * @date ：Created in 2022/8/9 14:18
 * @description：
 * @modified By：
 * @version:
 */
//@WebListener
public class MyListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //获得路径
        String realPath = sce.getServletContext().getRealPath("/");
        //将log4j导入进来
        String logPath = realPath+"/WEB-INF/classes/log4J.properties";
        PropertyConfigurator.configure(logPath);

        ApplicationContext ac = new ClassPathXmlApplicationContext("applicationContext.xml");
        sce.getServletContext().setAttribute("ac",ac);

        sce.getServletContext().setAttribute("abc","123123123123123");
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
        ServletContextListener.super.contextDestroyed(sce);
    }
}